const path = require("path");
const CompressionWebpackPlugin = require("compression-webpack-plugin"); // Gzip
const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); // 代码压缩

module.exports = {
  lintOnSave: false,
  publicPath: './',
  css: {
    loaderOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  devServer: {},

  chainWebpack: (config) => {
    // 自动化导入less
    const types = ["vue-modules", "vue", "normal-modules", "normal"];
    types.forEach((type) =>
      addStyleResource(config.module.rule("less").oneOf(type))
    );
  },
  pluginOptions: {
    mock: {
      entry: "./mock/index.js",
      debug: false,
      // disable: process.env.VUE_APP_MOCKJS == "true",
    },
    // 'style-resources-loader': {
    //     preProcessor: 'less',
    //     patterns: [
    //         path.join(__dirname, './src/assets/less/index.less')
    //     ]
    // }
  },
};

function addStyleResource(rule) {
  rule
    .use("style-resource")
    .loader("style-resources-loader")
    .options({
      patterns: [path.resolve(__dirname, "./src/assets/less/import.less")],
    });
}
